package com.treasure.hunt.api

import com.module.lemlin.mode.SubscribeListener
import com.module.lemlin.rxhttp.HttpServiceData
import com.treasure.hunt.entity.CardListResponse
import io.reactivex.rxjava3.disposables.Disposable
import com.treasure.hunt.api.subscribe.subscribe
import com.treasure.hunt.entity.CardGiveResponse
import com.treasure.hunt.entity.MergeResponse
import rxhttp.RxHttp


/**
 * 卡片列表
 * */
fun cardList(
    listener: SubscribeListener<CardListResponse>
): Disposable = subscribe(
    RxHttp.get("/api/cart/cart_list")
        .asClass(CardListResponse::class.java)
    , listener
)

/**
 * 万能卡兑换
 * */
fun cardExchange(
    cartId: Int, exchangeCartId: Int, listener: SubscribeListener<HttpServiceData>
): Disposable = subscribe(
    RxHttp.postForm("/api/cart/exchange_cart")
        .add("cart_id", cartId)
        .add("exchange_cart_id", exchangeCartId)
        .asClass(HttpServiceData::class.java)
    , listener
)

/**
 * 索取卡片
 * */
fun cardUserGiveCard(
    cartId: String,
    receiveUserId: String,
    listener: SubscribeListener<HttpServiceData>
) = subscribe(
    RxHttp.postForm("/api/cart/user_give_cart")
        .add("cart_id", cartId)
        .add("receive_user_id", receiveUserId)
        .asClass(HttpServiceData::class.java)
    , listener
)

/**
 * 领取卡片
 * */
fun cardReceiveCart(
    giveId: String,
    listener: SubscribeListener<HttpServiceData>
) = subscribe(
    RxHttp.postForm("/api/cart/receive_cart")
        .add("give_id", giveId)
        .asClass(HttpServiceData::class.java)
    , listener
)

/**
 * 赠送记录
 * */
fun cardGiveCartLog(
    page: Int, limit: Int, listener: SubscribeListener<CardGiveResponse>
): Disposable = subscribe(
    RxHttp.get("/api/cart/give_cart_log")
        .add("page", page)
        .add("limit", limit)
        .asClass(CardGiveResponse::class.java)
    , listener
)
